package babo.cd.physicalexperiment.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.bumptech.glide.Glide;
import com.contrarywind.listener.OnItemSelectedListener;
import com.contrarywind.view.WheelView;
import com.lxj.xpopup.core.BottomPopupView;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import babo.cd.physicalexperiment.R;
import babo.cd.physicalexperiment.data.MyEnventData;
import babo.cd.physicalexperiment.utils.Out;
import babo.cd.physicalexperiment.view.RoundAngleImageView;

public class YiqiJiaozhunDialog extends BottomPopupView {

    Context context;

    TextView tx_sure,tx_cancle,tx_name;
    WheelView wheelView1;
    long ctime=0;
    private String ctz="0";
    private int flagtz;

    public YiqiJiaozhunDialog(@NonNull Context context,int flagtz) {
        super(context);
        this.context=context;
        this.flagtz=flagtz;


    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialogyiqijiaozhun;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        tx_sure=(TextView)findViewById(R.id.tx_sure);
        tx_cancle=(TextView) findViewById(R.id.tx_cancle);
        wheelView1=(WheelView)findViewById(R.id.wh1);
        tx_name=(TextView)findViewById(R.id.tx_name);
        List<String> cts = new ArrayList<>();
        List<String> wts = new ArrayList<>();
        for (int i = -100; i <100 ; i++) {
            cts.add(i+"x 0.1mm");
        }

        if (flagtz==1){
            tx_name.setText("动镜左右调节");
        }
        if (flagtz==2){
            tx_name.setText("动镜上下调节");
        }
        if (flagtz==3){
            tx_name.setText("定镜左右调节");
        }
        if (flagtz==4){
            tx_name.setText("定镜上下调节");
        }

        wheelView1.setAdapter(new ArrayWheelAdapter(cts));
        wheelView1.setCyclic(true);
        wheelView1.setCurrentItem(100);
        wheelView1.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
              Out.out("粗调："+index+"  ==="+wheelView1.getAdapter().getItem(index).toString());

              ctz=wheelView1.getAdapter().getItem(index).toString();
             if (System.currentTimeMillis()-ctime>1500){
                 //todo 执行
             }
             ctime=System.currentTimeMillis();


            }
        });







        tx_cancle.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {

                dismiss();
            }
        });


        setLister();

    }

    private void setLister() {
        tx_sure.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                String cv=ctz.replace("x 0.1mm","");

                EventBus.getDefault().post(MyEnventData.getInstance("yiqijiaozhuna@"+flagtz+"@"+cv));
                dismiss();

            }
        });
    }


}
